<script setup>
import { useUserStore } from '@/stores'
import router from '@/router'
import { reactive } from 'vue'
import { useRoute } from 'vue-router'

const userId = useRoute().query.id

const UserStore = useUserStore()

const addressList = UserStore.userList.find((item) => item.id === userId)?.addressList

console.log(UserStore.userList)
console.log(addressList)
const formData = reactive({
  city: '',
  department: '',
  houseNumber: '',
  name: '',
  phone: ''
})
const keepAddress = () => {
  console.log(formData)
  const address = {
    name: formData.name,
    phone: formData.phone,
    address_text: `${formData.city} ${formData.department}${formData.houseNumber}`
  }
  console.log(address)
  addressList.push(address)
  router.go(-1)
}
</script>
<template>
  <div class="address-view">
    <div class="address-view-top">
      <div class="address-view-top-left iconfont" @click="$router.go(-1)">&#xe697;</div>
      <div class="address-view-top-center">新增收货地址</div>
      <div class="address-view-top-right" @click="keepAddress">保存</div>
    </div>
    <div class="address-view_form">
      <div class="form_item">
        <div class="form_item_label">所在城市:</div>
        <input
          type="text"
          class="form_item_content"
          placeholder="如北京市"
          v-model="formData.city"
        />
      </div>
      <div class="form_item">
        <div class="form_item_label">小区/大厦/学校:</div>
        <input
          type="text"
          class="form_item_content"
          placeholder="如理工大学国防科技园"
          v-model="formData.department"
        />
      </div>
      <div class="form_item">
        <div class="form_item_label">楼号-门牌号:</div>
        <input
          type="text"
          class="form_item_content"
          placeholder="如A号楼B层"
          v-model="formData.houseNumber"
        />
      </div>
      <div class="form_item">
        <div class="form_item_label">收货人:</div>
        <input
          type="text"
          class="form_item_content"
          placeholder="请填写收货人姓名"
          v-model="formData.name"
        />
      </div>
      <div class="form_item">
        <div class="form_item_label">联系电话:</div>
        <input
          type="text"
          class="form_item_content"
          placeholder="请填写收货手机号"
          v-model="formData.phone"
          maxlength="11"
        />
      </div>
    </div>
  </div>
</template>
<style scoped lang='scss'>
@import '@/style/viriables.scss';

.address-view {
  width: 100%;
  height: 100%;
  &-top {
    $height: 40px;
    font-size: 20px;
    line-height: $height;
    height: $height;
    display: flex;
    justify-content: space-between;
    background-color: #fff;
    padding: 0 10px;
    &-left {
      font-size: 24px;
    }
  }
  &_form {
    padding: 0 0.18rem;
    background-color: $bgColor;
    font-size: 0.14rem;
    font-weight: 800;

    .form_item {
      display: flex;
      padding: 0.12rem;
      line-height: 0.2rem;
      border-top: 0.01rem solid $content-bgColor;

      &_content {
        flex: 1;
        margin-left: 0.08rem;
        border: none;
        outline: none;
      }
    }
  }
}
</style>